extends CharacterBody2D
class_name MushroomCharacterBody

# 物理参数
var gravity: int = 980
var max_fall_speed: int = 500

# 状态
var falling: bool = false

# 节点引用
@onready var mushroom_animator = $Mushroom_animator
@onready var mushroom_drag = $Area2D
@onready var mushroom = $".."

func _physics_process(delta: float) -> void:
	if mushroom_drag:
		if not mushroom_drag.is_drag:
			apply_gravity(delta)
			move_and_slide()
			update_floor_stat()
	if falling:
		mushroom.set_mushroom_stat_falling()
		
		

# 当滞空时，添加重力
func apply_gravity(delta):
	if not is_on_floor():
		velocity.y += gravity * delta
		velocity.y = min(velocity.y, max_fall_speed)
	return
# 更新地面状态

func update_floor_stat():
	if is_on_floor():
		falling = false
		mushroom.set_mushroom_stat_waiting()
	else:
		falling = true
	return
